<template>
  <div class="view-fill">
    <div class="app-container-flex">
      <NewFullScreen v-model="showDialog" :title="title">
        <template v-slot:full-button>
          <el-button
            v-if="$permission('deliverOrderDetail:printOrderDetail')"
            @click="print"
            >打印</el-button
          >
          <el-button
            v-if="$permission('deliverOrderDetail:excelOrderDetail')"
            @click="exportExcel"
            >导出excel</el-button
          >
        </template>
        <div class="model-panel">
          <div class="model-panel-title">
            <p>{{ $t('basic_information') }}</p>
          </div>
          <div class="model-panel-body">
            <BasicInformation :info="infoList"></BasicInformation>
          </div>
        </div>
        <div class="model-panel">
          <div class="model-panel-title">
            <p>{{ $t('detailInfo') }}</p>
          </div>
          <div class="model-panel-body">
            <div class="layui-card-body">
              <!-- 表格 -->
              <PageTable
                :refresh="tableInfo.refresh"
                :init-curpage="tableInfo.initCurpage"
                v-model:data="tableInfo.data"
                :pager="false"
                :field-list="tableInfo.fieldList"
                :handle="tableInfo.handle"
                :check-box="false"
                :tab-index="true"
                :isDynamic="true"
              >
              </PageTable>
            </div>
          </div>
        </div>
      </NewFullScreen>
    </div>
  </div>
</template>

<script setup name="deliverOrderDetails">
import { getCustomizeSetting } from '@/api/customize'
import {
  excelDetailDeliverOrder,
  getDeliverOrderById,
  getDeliverOrderDetailCustomizeListAll,
  printDetailDeliverOrder,
} from '@/api/supplier.js'
import { fatchTemplateByCode, getRrgUserAll } from '@/api/base'
const props = defineProps(['visible', 'tableId'])
const { proxy } = getCurrentInstance()
const title = ref('发货单详情')
const infoList = ref({
  data: {},
  fieldList: [
    { label: '发货单号', value: 'orderNo', type: 'text' },
    { label: '销售单号', value: 'saleNo', type: 'text' },
    { label: '采购单号', value: 'purchNo', type: 'text' },
    { label: '发票号码', value: 'invoiceNumber', type: 'text' },
    { label: '货单号码', value: 'waybillNumber', type: 'text' },
    { label: '客户', value: 'hospitalName', type: 'text' },
    { label: '客户部门', value: 'deptName', type: 'text' },
    { label: '预计发货日期', value: 'expectedDeliverTime', type: 'text' },
    { label: '收货地址', value: 'receiveAddressValue', type: 'text' },
    { label: '收货联系人', value: 'receiveContacts', type: 'text' },
    { label: '联系人电话', value: 'receivePhone', type: 'text' },
    { label: '创建人', value: 'createUserName', type: 'text' },
    { label: '创建时间', value: 'createTime', type: 'text' },
    { label: '状态', value: 'statusValue', type: 'text' },
    {
      label: '是否寄售业务',
      value: 'isConsignBusinessValue',
      type: 'text',
      show: proxy.$store.state.permission.systemConfig.is_consign_business == 1,
    },
    {
      label: '备注',
      value: 'remark',
      type: 'popover',
    },
  ],
})
const tableInfo = ref({
  refresh: 1,
  initCurpage: 1,
  data: [],
  fieldList: [],
})
const filterInfo = ref({
  query: {
    customizeUserVO: {},
    queryMap: {
      orderId: {
        queryType: 'EQUALS',
        queryCategory: 'AND',
        value: props.tableId,
      },
    },
    queryParams: {},
  },
})
const showDialog = computed({
  get() {
    return props.visible
  },
  set(val) {
    proxy.$emit('update:visible', val) // 更新父组件visible
  },
})
//导出excel
async function exportExcel() {
  excelDetailDeliverOrder(filterInfo.value.query).then((resp) => {
    if (resp) {
      proxy.$fn.parseExcel(resp)
    }
  })
}
//打印
function print() {
  fatchTemplateByCode({
    resourceCode: 'deliverOrderDetail:printOrderDetail',
    isDefault: 1,
  }).then((res) => {
    if (res && res.success) {
      let temp = proxy.$fn.getPrintTemp(res.data[0])
      getPrintData(temp)
    }
  })
}
function getPrintData(temp) {
  let params = {
    tableKey:
      'supplierDeliverOrderDetail-com.slip.spd.entity.vo.supplier.DeliverOrderDetailVO',
    orderIds: [props.tableId],
  }
  printDetailDeliverOrder(params).then((res) => {
    if (res.success && res) {
      let data = proxy.$fn.deepClone(res.data)
      let newData = data.map((item) => {
        return {
          ...item,
          ...item.orderInfo,
        }
      })
      proxy.$lodop.preview(temp, newData)
    }
  })
}
function getList() {
  getDeliverOrderDetailCustomizeListAll(filterInfo.value.query).then((resp) => {
    if (resp && resp.success) {
      tableInfo.value.data = resp.data
    }
  })
}

function getMain() {
  getDeliverOrderById(props.tableId).then((resp) => {
    if (resp && resp.success) {
      infoList.value.data = resp.data
    }
  })
}
function returnModify() {
  getMain()
  getList()
}
function getCustomize() {
  let param = {
    tableKey:
      'supplierDeliverOrderDetail-com.slip.spd.entity.vo.supplier.DeliverOrderDetailVO',
  }
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data
      filterInfo.value.query.customizeUserVO = data
      let obj = proxy.$fn.setFieldList(
        tableInfo.value.fieldList,
        data.detail,
        true
      )
      tableInfo.value.fieldList = obj.fieldList
      getMain()
      getList()
    }
  })
}
let obj = {}
tableInfo.value.fieldList = Object.values({
  ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
  ...obj,
})
getCustomize()
</script>

<style scoped></style>
